#include "mythread.h"
#include <QDebug>


QMutex myThread::mutex;
int myThread::num = 0;

myThread::myThread(QObject *parent)
    : QThread{parent}
{}

void myThread::run()
{
    while(1)
    {
        // this->mutex.lock(); //加锁

        // qDebug() << "Current Thread: "<< this << ", Value" << this->num++;

        // this->mutex.unlock(); //解锁

        {
            QMutexLocker lock(&this->mutex);
            qDebug() << "Current Thread: "<< this << ", Value" << this->num++;
        }
        QThread::sleep(1); //线程睡眠两秒
    }
}
